package com.neiquan.weiguan.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.neiquan.weiguan.R;
import com.neiquan.weiguan.activity.ContainerActivity;
import com.neiquan.weiguan.fragment.ImageDetailsFragment;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;

/**
 * Created by wyl on 2016/7/2.
 * 我的--->新闻适配器
 */
public class NewsAdapter extends MyBaseAdapter<String> implements View.OnClickListener {
    private Context context;
    private List<String> data;
    private static final int TAG_ONE = 0;
    private static final int TAG_TWO = 1;
    private static final int TAG_THREE = 2;
    private static final int TAG_FOUR = 3;
    private static final int TAG_FIVE = 4;
    private int[] ints = {0, 1, 2, 3, 4};

    public NewsAdapter(Context context, List<String> data) {
        super(context, data);
        this.context = context;
        this.data = data;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = null;
        switch (viewType) {
            case TAG_ONE:
                view = LayoutInflater.from(context).inflate(R.layout.new_list_item_one, null);
                return new NewItemOneViewHolder(view);
            case TAG_TWO:
                view = LayoutInflater.from(context).inflate(R.layout.new_list_item_two, null);
                return new NewItemTwoViewHolder(view);
            case TAG_THREE:
                view = LayoutInflater.from(context).inflate(R.layout.new_list_item_three, null);
                return new NewItemThreeViewHolder(view);
            case TAG_FOUR:
                view = LayoutInflater.from(context).inflate(R.layout.new_list_item_four, null);
                return new NewItemFourViewHolder(view);
            case TAG_FIVE:
                view = LayoutInflater.from(context).inflate(R.layout.new_list_item_five, null);
                return new NewItemFiveViewHolder(view);
        }
        return null;
    }

    @Override
    public int getItemViewType(int position) {
        return ints[position];
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof NewItemFiveViewHolder) {
            NewItemFiveViewHolder fiveViewHolder = (NewItemFiveViewHolder) holder;
            fiveViewHolder.rel_new_list_item_rootview_five.setOnClickListener(this);
        }
    }

    @Override
    public int getItemCount() {
        return 5;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rel_new_list_item_rootview_five:
                ContainerActivity.startActivity(context, ImageDetailsFragment.class, null);
                break;
        }
    }

    public class NewItemOneViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.rel_new_list_item_rootview_one)
        LinearLayout rel_new_list_item_rootview_one;
        @InjectView(R.id.text_new_list_item_title_one)
        TextView mTextNewListItemTitleOne;
        @InjectView(R.id.text_new_list_item_author_one)
        TextView mTextNewListItemAuthorOne;
        @InjectView(R.id.text_new_list_item_commentcount_one)
        TextView mTextNewListItemCommentcountOne;
        @InjectView(R.id.text_new_list_item_time_one)
        TextView mTextNewListItemTimeOne;
        @InjectView(R.id.text_new_list_item_comment_one)
        ImageView mTextNewListItemCommentOne;

        public NewItemOneViewHolder(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
        }
    }

    public class NewItemTwoViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.rel_new_list_item_rootview_two)
        LinearLayout rel_new_list_item_rootview_two;
        @InjectView(R.id.text_new_list_item_title_two)
        TextView mTextNewListItemTitleTwo;
        @InjectView(R.id.text_new_list_item_author_two)
        TextView mTextNewListItemAuthorTwo;
        @InjectView(R.id.text_new_list_item_commentcount_two)
        TextView mTextNewListItemCommentcountTwo;
        @InjectView(R.id.text_new_list_item_time_two)
        TextView mTextNewListItemTimeTwo;
        @InjectView(R.id.text_new_list_item_comment_two)
        ImageView mTextNewListItemCommentTwo;
        @InjectView(R.id.img_new_list_item_pic_two)
        ImageView mImgNewListItemCommentTwo;

        public NewItemTwoViewHolder(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
        }
    }

    public class NewItemThreeViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.rel_new_list_item_rootview_three)
        LinearLayout rel_new_list_item_rootview_three;
        @InjectView(R.id.text_new_list_item_title_three)
        TextView mTextNewListItemTitleThree;
        @InjectView(R.id.new_list_item_videoplayer_three)
        JCVideoPlayer mNewListItemVideoplayerThree;
        @InjectView(R.id.text_new_list_item_author_three)
        TextView mTextNewListItemAuthorThree;
        @InjectView(R.id.text_new_list_item_commentcount_three)
        TextView mTextNewListItemCommentcountThree;
        @InjectView(R.id.text_new_list_item_time_three)
        TextView mTextNewListItemTimeThree;
        @InjectView(R.id.text_new_list_item_comment_three)
        ImageView mTextNewListItemCommentThree;

        public NewItemThreeViewHolder(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
        }
    }

    public class NewItemFourViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.rel_new_list_item_rootview_four)
        LinearLayout rel_new_list_item_rootview_four;
        @InjectView(R.id.text_new_list_item_title_four)
        TextView mTextNewListItemTitleFour;
        @InjectView(R.id.img_new_list_item_pic_one_four)
        ImageView mImgNewListItemPicOneFour;
        @InjectView(R.id.img_new_list_item_pic_two_four)
        ImageView mImgNewListItemPicTwoFour;
        @InjectView(R.id.img_new_list_item_pic_three_four)
        ImageView mImgNewListItemPicThreeFour;
        @InjectView(R.id.text_new_list_item_author_four)
        TextView mTextNewListItemAuthorFour;
        @InjectView(R.id.text_new_list_item_commentcount_four)
        TextView mTextNewListItemCommentcountFour;
        @InjectView(R.id.text_new_list_item_time_four)
        TextView mTextNewListItemTimeFour;
        @InjectView(R.id.text_new_list_item_comment_four)
        ImageView mTextNewListItemCommentFour;

        public NewItemFourViewHolder(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
        }
    }

    public class NewItemFiveViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.rel_new_list_item_rootview_five)
        LinearLayout rel_new_list_item_rootview_five;
        @InjectView(R.id.text_piccount_five)
        TextView mTextPiccountFive;
        @InjectView(R.id.rel_new_list_item_pic_five)
        RelativeLayout mRelNewListItemPicFive;
        @InjectView(R.id.text_new_list_item_title_five)
        TextView mTextNewListItemTitleFive;

        public NewItemFiveViewHolder(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
        }
    }
}
